/**
 * Created by John on 2016/6/14.
 */
var mongo = new Mongo("localhost");
var db = mongo.getDB("BeginningMongoDB");
var wordStats = db.getCollection("word_stats");

print("\nFor Each List: ");
var cursor = wordStats.find();
cursor.forEach(function (word) {
    print("word: " + word.word);
});

print("\nMapped Array: ");
cursor = wordStats.find();
words = cursor.map(function (word) {
    return word.word;
});
printjson(words);

print("\nIndexed Document in Array: ");
cursor = wordStats.find();
words = cursor.toArray();
print(JSON.stringify(words[15]));

print("\nNext Document in Cursor: ");
cursor = wordStats.find();
var word = cursor.next();
print(JSON.stringify(word));